<!doctype html>
<html lang="zh-CH">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>央票通</title>
	<link rel="stylesheet" href="./resource/css/index.css">
	<link rel="stylesheet" href="./resource/css/user_name.css">
</head>
<body>
<!-- 头部 -->
@include('common.index_head')
<!-- 个人中心 -->
<div class="cont-user">
	<div class="user-name">
		<div class="main">
			<div class="name-cont">
				<div class="title">
					<span>身份验证</span>
				</div>
				<div class="form">
					<form action="/username_auth_two" method="post" onsubmit="return check_all()">
						<span id="t_name"></span>
						<div class="form-group">
							<label for=""><span>*</span>真实姓名</label>
							<input type="text" class="form-control" name="real_name" id="real_name">
						</div>
						<div class="form-group">
							<label for=""><span>*</span>身份证号</label>
							<input type="text" class="form-control" name="id_card" id="id_card">
						</div>
						<button type="submit" class="btn btn-register">下一步</button>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- footer -->
@include('common.index_foot')
<script src="./resource/js/jquery-1.11.3.min.js"></script>
<script src="./resource/js/index.js"></script>
<script>

function check_all()
{
	var real_name = document.getElementById('real_name').value;
	var id_card = document.getElementById('id_card').value;
	var reg_name = /^[\u4e00-\u9fa5]{1,9}$/;
	var reg_id = /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/;
	var status = false
	if(reg_name.test(real_name)){
		if(reg_id.test(id_card)){
			var ajax = new XMLHttpRequest();
			ajax.onreadystatechange = function () {
				if (ajax.readyState == 4) {
					if (ajax.responseText == 0) {
						document.getElementById('t_name').innerHTML = "<span style='color:red'>身份证号和姓名不一致</span>";
					}else if(ajax.responseText == 1){
						document.getElementById('t_name').innerHTML = "<span style='color:red'>该身份证已经绑定</span>";
					}else if(ajax.responseText == 2){
						document.getElementById('t_name').innerHTML = "<span style='color:red'>已经实名认证</span>";
					}else{
						document.getElementById('t_name').innerHTML = "";
						status = false;
					}
				}
			}
			//与服务器建立连接
			ajax.open('post', '/real_name_auth', false);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			//处理请求
			ajax.send('real_name=' + real_name+"&id_card="+id_card);
			return status
		}else{
			document.getElementById('t_name').innerHTML = "<span style='color:red'>请输入正确的身份证号</span>";
			return false;
		}
	}else{
		document.getElementById('t_name').innerHTML = "<span style='color:red'>请输入有效姓名</span>";
		return false;
	}

}
</script>
</body>
</html>